package com.swak.consistency.reliablemsg.context;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 事务阶段
 * 
 * @author DELL
 */
@RequiredArgsConstructor
@Getter
public enum Phase {

	/**
	 * 准备阶段
	 */
	Prepare(0),

	/**
	 * 消息确认
	 */
	Confirm(1),

	/**
	 * 消息取消
	 */
	Cancel(2);

	private final int code;

	public static Phase valueOf(int code) {
		Phase[] phases = Phase.values();
		for (Phase phase : phases) {
			if (phase.getCode() == code) {
				return phase;
			}
		}
		return null;
	}
}
